package cn.zhouchao.system.controller;

import cn.zhouchao.basic.util.AjaxResult;
import cn.zhouchao.basic.util.PageList;
import cn.zhouchao.system.domain.Systemdictionarytype;
import cn.zhouchao.system.query.SystemdictionarytypeQuery;
import cn.zhouchao.system.service.ISystemdictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/sdt")
public class SystemdictionarytypeController {
    @Autowired
    private ISystemdictionarytypeService systemdictionarytypeService;
    //查询全部数据类型
    @GetMapping
    public List<Systemdictionarytype> findAll(){
        return systemdictionarytypeService.findAll();
    }

    //根据id查询数据类型
    @GetMapping("/{id}")
    public Systemdictionarytype findById(@PathVariable("id") Long id){
        return systemdictionarytypeService.findById(id);
    }

    // 新增数据类型
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarytype systemDictionaryType){
        if(null==systemDictionaryType.getId()){
            systemdictionarytypeService.add(systemDictionaryType);
        }else {
            systemdictionarytypeService.update(systemDictionaryType);
        }
        return new AjaxResult().success();
    }

    // 删除数据类型
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Long id){
        systemdictionarytypeService.deletes(id);
        return new AjaxResult().success();
    }

    // 批量删除数据类型
    @PatchMapping
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        systemdictionarytypeService.batchDelete(ids);
        return new AjaxResult().success();
    }

    // 分页
    @PostMapping
    public PageList<Systemdictionarytype> pageQuery(@RequestBody SystemdictionarytypeQuery systemdictionarytypeQuery){
        return systemdictionarytypeService.queryByPage(systemdictionarytypeQuery);
    }
}
